// @ts-ignore
/* eslint-disable */
import {request} from '@umijs/max';

/** addApi POST /api/api/add */
export async function addApiUsingPOST(
  params: API.addApiUsingPOSTParams,
  body: {},
  file?: File,
  options?: { [key: string]: any
}) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      formData.append(
        ele,
        typeof item === 'object' && !(item instanceof File) ? JSON.stringify(item) : item,
      );
    }
  });

  return request<API.BaseResponseLong_>('/api/api/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/octet-stream',
    },
    params: {
      ...params,
    },
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}

/** deleteApi POST /api/api/delete */
export async function deleteApiUsingPOST(
  body: API.DeleteRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseBoolean_>('/api/api/delete', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** getApiById GET /api/api/get */
export async function getApiByIdUsingGET(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.getApiByIdUsingGETParams,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseApi_>('/api/api/get', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** invokeInterfaceInfo POST /api/api/invoke */
export async function invokeInterfaceInfoUsingPOST(
  body: API.ApiInvokeRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseObject_>('/api/api/invoke', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** listApi POST /api/api/list */
export async function listApiUsingPOST(
  body: API.ApiQueryRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseListApi_>('/api/api/list', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** listApiByPage POST /api/api/list/page */
export async function listApiByPageUsingPOST(
  body: API.ApiQueryRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponsePageApi_>('/api/api/list/page', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** offlineInterfaceInfo POST /api/api/offline */
export async function offlineInterfaceInfoUsingPOST(
  body: API.IdRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseBoolean_>('/api/api/offline', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** onlineInterfaceInfo POST /api/api/online */
export async function onlineInterfaceInfoUsingPOST(
  body: API.IdRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseBoolean_>('/api/api/online', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** updateApi POST /api/api/update */
export async function updateApiUsingPOST(
  params: API.ApiUpdateRequest,
  body: {},
  file?: File,
  options?: { [key: string]: any },
) {

  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      formData.append(
        ele,
        typeof item === 'object' && !(item instanceof File) ? JSON.stringify(item) : item,
      );
    }
  });

  return request<API.BaseResponseBoolean_>('/api/api/update', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/octet-stream',
    },
    params: {
      ...params,
    },
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}
